Skip to content

Conversation

@Robbepop
Copy link
Member

@Robbepop Robbepop commented Sep 10, 2025

Wasmi IR 3.0 definitions: #1650

Closed Issues

Closes #1598
Closes #1632
Closes #1639
Closes #1516
Closes #1485
Closes #1433
Closes #1324

Potential optimizations:

  • Use same ip in execution handlers as in op-decode. (🟢 -11% fibonacci/iter)
  • Integrate instance stack in CallStack into frames. (easy)
  • Return TrapCode::OutOfSystemMemory in Stack operations where necessary.
  • Redesign portable-dispatch to avoid state copy and improve performance. (medium)
  • Properly use extra-checks for technically-infallible conditional panics. (easy)
  • Use byte-offsets for Slot type to avoid mul-by-8 during execution. (easy)
  • Use extern "sysv64" ABI for execution handlers on Windows. (medium)
  • Use variable sized cell load/stores for 32-bit operands: Implement variable sized VM registers #1671
  • Make Wasmi IR Instance related instead of Module related: Move Wasm function details into the Store #1492

Development Notes

  • Interpretation loop must be panic-free for tail calls to be properly generated without the become keyword.
    • This means that we have to wrap host function calls with ::core::panic::catch_unwind and convert potential panics into flags signalling bad state to the interpreter.
    • Furthermore, we need to establish a way to signal to the interpretation loop that we are in an error state (e.g. encountered a bug) and have to exit the interpretation loop safely before resolving the bug, e.g. via panicking.

ToDo

Fix known bugs:

  • Fix bugs with branch operator execution.
    • Likely, the branch offsets are incorrect.
  • Fix integer-overflow in Wasmi translator.
  • Fix execution issue with recursive operation sequences.
  • Fix bug in stripping start and end of copy_span values in translator.
  • Fix bugs leading to incorrect reverse_complement result.
  • Fix bugs leading to incorrect regex_redux result.

Implement Functionality

  • Calling host functions from root.
  • Calling and resuming of resumable functions.
    • Calling functions resumably.
    • Resuming after out of fuel.
    • Resuming after host error.
  • Calling host functions from within Wasm functions.
    • call_imported
    • call_indirect
    • return_call_imported
    • return_call_indirect
  • Missing Wasmi IR execution handlers
    • br_table operators
    • return_call* operators
    • bulk memory operators
    • bulk table operators
    • simd operators
    • relaxed-simd operators
    • wide-arithmetic operators

Preliminary Benchmarks

Preliminary benchmarks of this WIP state pre-optimization shows interesting results:

execute/fibonacci/iter

Crate Features PR main %
578us 705us 🟢 -18%
compact 840us - 🔴 +19%
trampolines 1.92ms - 🔴 x2.7
compact+trampolines 1.8ms - 🔴 x2.6

execute/fibonacci/rec

Crate Features PR main %
2.84ms 3.77ms 🟢 -24%
compact 4.10ms - 🔴 +8%
trampolines 5.32ms - 🔴 +41%
compact+trampolines 6.3ms - 🔴 +67%

execute/fibonacci/tail

Crate Features PR main %
481us 777us 🟢 -38%
compact 728us - 🟢 -7%
trampolines 1.04ms - 🔴 +34%
compact+trampolines 1.26ms - 🔴 +62%

execute/tiny_keccak

Crate Features PR main %
114us 193ms 🟢 -41%
compact 183us - 🟢 -4%
trampolines 421ms - 🔴 x2.18
compact+trampolines 360ms - 🔴 x1.87

Benchmarks Conclusion

  • The tail-call-based direct-dispatch outperforms main significantly.
  • The tail-call-based indirect-dispatch is somewhat on par with main.
  • Both trampoline-based dispatches are wastly outperformed by main.
    • Note: the reason partly is really bad codegen due to unnecessary register copies which should be fixable.

@Robbepop Robbepop marked this pull request as draft September 10, 2025 08:21
@Robbepop Robbepop mentioned this pull request Sep 11, 2025
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 7 times, most recently from 41aad7c to bb8b966 Compare September 18, 2025 10:11
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 2 times, most recently from 12a19d4 to 64f420e Compare September 19, 2025 14:54
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 2 times, most recently from 48242ca to 4d2d316 Compare October 4, 2025 10:55
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch from 7bfb899 to c32c7c7 Compare October 24, 2025 13:52
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 4 times, most recently from d9ec934 to c68956c Compare November 2, 2025 23:40
Robbepop added a commit that referenced this pull request Nov 8, 2025
* improve debug_assert failure message

* fix field ordering of TableSet operations

* add #[inline(always)] to decode impl

Benchmarks show significant performance improvements.

* add #[inline(always)] to TryFrom<u16> for OpCode

* improve code formatting in match

* add trivial {Read,Write}As impls for UntypedVal

* add From<Memory> for u32 impl

* apply rustfmt
@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch 2 times, most recently from 12257b9 to 7a87159 Compare November 10, 2025 12:43
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 83.47768% with 248 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.48%. Comparing base (099194d) to head (89a95ff).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
crates/wasmi/src/engine/translator/comparator.rs 40.66% 89 Missing ⚠️
crates/wasmi/src/engine/executor/handler/state.rs 88.42% 33 Missing ⚠️
crates/wasmi/src/engine/executor/handler/func.rs 73.04% 31 Missing ⚠️
crates/wasmi/src/engine/executor/handler/exec.rs 93.81% 30 Missing ⚠️
crates/wasmi/src/engine/executor/mod.rs 77.14% 16 Missing ⚠️
.../wasmi/src/engine/executor/handler/dispatch/mod.rs 77.19% 13 Missing ⚠️
crates/wasmi/src/engine/executor/handler/eval.rs 81.25% 12 Missing ⚠️
...c/engine/executor/handler/dispatch/backend/loop.rs 77.27% 5 Missing ⚠️
crates/wasmi/src/engine/translator/func/encoder.rs 54.54% 5 Missing ⚠️
crates/wasmi/src/engine/translator/func/visit.rs 69.23% 4 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1655      +/-   ##
==========================================
- Coverage   70.61%   62.48%   -8.14%     
==========================================
  Files         180      164      -16     
  Lines       15338    13200    -2138     
==========================================
- Hits        10831     8248    -2583     
- Misses       4507     4952     +445     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Robbepop Robbepop force-pushed the rf-integrate-wasmi-ir-3.0 branch from 23af6c2 to 75ab76b Compare November 14, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment